﻿using System;
using System.Collections;
using System.Collections.Generic;
using BLL;
using CrystalDecisions.CrystalReports.Engine;
using Model;

public partial class ViewbyProduct_ViewPIM_PIMTestView_ExportbyDT : System.Web.UI.Page
{
    private DateTime dt1, dt2;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.CrystalReportViewer1.Visible = false;
        }
        this.Page.Unload += new EventHandler(Page_Unload);
    }

    void Page_Unload(object sender, EventArgs e)
    {
        this.CrystalReportSource1.Dispose();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        dt1 = DateTime.Parse(this.TextBox1.Value.Trim());
        dt2 = DateTime.Parse(this.TextBox2.Value.Trim());
        ForCrystalReport();
        this.CrystalReportViewer1.Visible = true;
    }

    protected void ForCrystalReport()
    {
        CrystalReportSource1.ReportDocument.Load(Server.MapPath("PIMTestView_ExportbyDT.rpt"));

        TextObject txtTestTime = (TextObject)this.CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Text11"];
        txtTestTime.Text = dt1.ToString() + "-" + dt2.ToString();

        IList<PIMTestInfo> list = GetTestData();
        CrystalReportSource1.ReportDocument.SetDataSource(list);
        CrystalReportSource1.DataBind();
        this.CrystalReportViewer1.ReportSource = CrystalReportSource1;
        CrystalReportViewer1.DataBind();
    }

    public IList<PIMTestInfo> GetTestData()
    {
        IList<PIMTestInfo> tests = new List<PIMTestInfo>();
        PIMTest test = new PIMTest();
        tests = test.GetPIMTestbyDT(dt1, dt2);
        return tests;
    }
}
